package com.example.administrator.newsdemo;


import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

import com.example.administrator.newsdemo.cn.gdcp.fragments.CaiJingFragment;
import com.example.administrator.newsdemo.cn.gdcp.fragments.GuoJiFragment;
import com.example.administrator.newsdemo.cn.gdcp.fragments.GuoNeiFragment;
import com.example.administrator.newsdemo.cn.gdcp.fragments.HeadlineFragment;
import com.example.administrator.newsdemo.cn.gdcp.fragments.JunShiFragment;
import com.example.administrator.newsdemo.cn.gdcp.fragments.KeJiFragment;
import com.example.administrator.newsdemo.cn.gdcp.fragments.SheHuiFragment;
import com.example.administrator.newsdemo.cn.gdcp.fragments.ShiShangFragment;
import com.example.administrator.newsdemo.cn.gdcp.fragments.TiYuFragment;
import com.example.administrator.newsdemo.cn.gdcp.fragments.YuLeFragment;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {
    private TabLayout myTab;
    private ViewPager viewPager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        List<Fragment> fragments = new ArrayList<>();
        fragments.add(new HeadlineFragment());
        fragments.add(new SheHuiFragment());
        fragments.add(new GuoNeiFragment());
        fragments.add(new GuoJiFragment());
        fragments.add(new YuLeFragment());
        fragments.add(new TiYuFragment());
        fragments.add(new JunShiFragment());
        fragments.add(new KeJiFragment());
        fragments.add(new CaiJingFragment());
        fragments.add(new ShiShangFragment());
        TitleFragmentAdapter adapter = new TitleFragmentAdapter(getSupportFragmentManager(),fragments,new String[]{"头条","社会","国内","国际","娱乐","体育","军事","科技","财经","时尚"});
        viewPager.setAdapter(adapter);
        myTab.setupWithViewPager(viewPager);
    }

    private void initView() {
        myTab = (TabLayout) findViewById(R.id.tab);
        viewPager = (ViewPager) findViewById(R.id.viewpager);
    }
}
